package org.song.config;

import org.song.interceptor.WebContextInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author song
 * @date 2022/3/7 13:54
 * 拦截器配置添加自定义拦截器链 设置自定义拦截路径
 **/
 @Configuration  // 声明spring配置类注入spring容器
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 注入自定义拦截器到spring容器
     * @return
     */
    @Bean
    public WebContextInterceptor webContextInterceptor() {
        return new WebContextInterceptor();
    }

    /**
     * 添加自定义拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截器并设置拦截路径
        registry.addInterceptor( this.webContextInterceptor() ).excludePathPatterns(
                "/"
        );
        // 添加拦截器并设置拦截路径
       /* registry.addInterceptor( responseParamInterceptor() ).excludePathPatterns(
                "/"
        );*/

    }
}
